﻿using System;
using System.Runtime.Serialization;

namespace O1.Kernel.IO.KeyGeneration
{
    [Serializable]
    public class SnowflakeException : Exception
    {
        public SnowflakeException() : base()
        {
            this.ExceptionId = Guid.NewGuid();
        }

        public SnowflakeException(string message, Exception innerException)
            : base(message, innerException)
        {
            this.ExceptionId = Guid.NewGuid();
        }

        public SnowflakeException(string message) 
            : base(message)
        {
            this.ExceptionId = Guid.NewGuid();
        }

        protected SnowflakeException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            this.ExceptionId = (Guid)info.GetValue("ExceptionId", typeof(Guid));
            this.HasBeenLogged = info.GetBoolean("HasBeenLogged");
        }

        public Guid ExceptionId { get; private set; }

        public bool HasBeenLogged { get; set; }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            info.AddValue("ExceptionId", this.ExceptionId);
            info.AddValue("HasBeenLogged", this.HasBeenLogged);
            base.GetObjectData(info, context);
        }
    }
}